<?php

use Medoo\Medoo;
require_once __DIR__ . '/../vendor/autoload.php';

$filter  = array();
/* 过滤关键字读取开始 */
$file = __DIR__ . '/../.env';
if (file_exists($file)){
    $file_handle = fopen($file, "r");
    while (!feof($file_handle)) {
        $line = fgets($file_handle);
        $str = trim($line);
        if(empty($str)) continue;
        $arr = explode('=', trim($line));
        $filter[$arr[0]] = $arr[1] ?? '';
    }
    fclose($file_handle);
}
/* 过滤关键字读取结束   */
// var_dump($filter);
$env_config = $filter;
if(empty($env_config['DB_CONNECTION'])) {
    exit('请检查服务器配置');
}

$DB = new Medoo([
    'database_type' => $env_config['DB_CONNECTION'],
    'database_name' => $env_config['DB_DATABASE'],
    'server' => $env_config['DB_HOST'],
    'username' => $env_config['DB_USERNAME'],
    'password' => $env_config['DB_PASSWORD'],
    'charset' => 'utf8',
]);

?>
